<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:if="${date} ne null">修改线路</title>
    <title th:if="${date} eq null">新增线路</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <script src="../js/jquery.min.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-card-header" th:if="${date} ne null">修改线路</div>
            <div class="layui-card-header" th:if="${date} eq null">新增线路</div>
            <div class="layui-col-md12">
                <div class="layui-card" style="padding-bottom: 1px">
                    <div class="layui-card-body ">
                        <form class="layui-form" id="formDate">
                            <input type="hidden" name="id" id="id" th:value="${date==null?0:date.id}">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">线路编号：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="lineCode" id="lineCode"
                                               th:value="${date==null?'':date.lineCode}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">线路名称：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="lineName" id="lineName"
                                               th:value="${date==null?'':date.lineName}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">线路长度：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="lineLength" id="lineLength"
                                               th:value="${date==null?'':date.lineLength}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">回路长度：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="backLength" id="backLength"
                                               th:value="${date==null?'':date.backLength}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">投运日期：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="productDate" id="productDate"
                                               th:value="${date==null?'':#dates.format(date.productDate, 'yyyy-MM-dd')}"
                                               autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">电压等级：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="voltageLevel" id="voltageLevel"
                                               th:value="${date==null?'':date.voltageLevel}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">起始杆号：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="startPoleCode" id="startPoleCode"
                                               th:value="${date==null?'':date.startPoleCode}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">终止杆号：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="endPoleCode" id="endPoleCode"
                                               th:value="${date==null?'':date.endPoleCode}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">塔基数：</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="towerBaseNum" id="towerBaseNum"
                                               th:value="${date==null?'':date.towerBaseNum}" autocomplete="off">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">备注：</label>
                                    <div class="layui-input-inline">
                                        <textarea class="layui-textarea" name="common" id="common"
                                                  th:value="${date==null?'':date.common}" autocomplete="off"></textarea>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">是否启用：</label>
                                    <div th:if="${date!=null}" class="layui-input-block">
                                        <input type="radio" name="isStart" value="1"
                                               th:attr="checked=${date.isStart==1?true:false}" title="启用">
                                        <input type="radio" name="isStart" value="0"
                                               th:attr="checked=${date.isStart==0?true:false}" title="停用">
                                    </div>
                                    <div th:if="${date==null}" class="layui-input-block">
                                        <input type="radio" name="isStart" value="1" checked="checked" title="启用">
                                        <input type="radio" name="isStart" value="0" title="停用">
                                    </div>
                                </div>
                                <br/>
                                <div class="layui-form-item layui-inline" >
                                    <button class="layui-btn" lay-submit="" lay-filter="add">保存</button>
                                    <button class="layui-btn" onclick="javascript:history.back();">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        layui.use(['form', 'layedit', 'laydate'],function(){
            var form = layui.form;
            var table=layui.table;

            form.render('radio');
            var geshi=/^((19\d{2})|(200\d)|(201[0-6]))-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[01])$/;
            form.on('submit(add)', function(data){
                var fd=data.field;

                if(fd.lineCode==""){
                    layer.msg("请输入线路编号！");
                    return false;
                }
                if(fd.lineName==""){
                    layer.msg("请输入线路名称！");
                    return false;
                }
                if(fd.lineLength==""){
                    layer.msg("请输入线路长度！");
                    return false;
                }
                if(fd.backLength==""){
                    layer.msg("请输入回路长度！");
                    return false;
                }
                if(fd.productDate==""){
                    layer.msg("请输入投运日期！");
                    return false;
                }else if(!geshi.test(fd.productDate)){
                    layer.msg("投运日期格式必须为 yyyy-MM-dd！");
                    return false;
                }
               // fd.productDate=StringToDate(fd.productDate);

                if(fd.voltageLevel==""){
                    layer.msg("请输入电压等级！");
                    return false;
                }
                if(fd.startPoleCode==""){
                    layer.msg("请输入起始杆号！");
                    return false;
                }
                if(fd.endPoleCode==""){
                    layer.msg("请输入终止杆号！");
                    return false;
                }
                if(fd.towerBaseNum==""){
                    layer.msg("请输入塔基数！");
                    return false;
                }

                var productDate= new Date(Date.parse(fd.productDate.replace(/-/g,   "/")));

                $.ajax({
                    type:"POST",
                    url:'/line/upDate',
                    data: {"id":fd.id,"lineCode":fd.lineCode,"lineName":fd.lineName,"lineLength":fd.lineLength,
                            "backLength":fd.backLength,"productDate":productDate,"voltageLevel":fd.voltageLevel,
                            "startPoleCode":fd.startPoleCode,"endPoleCode":fd.endPoleCode,"towerBaseNum":fd.towerBaseNum
                            },
                    async: false,
                    contentType:'application/json;charset=UTF-8',
                    dataType:'json',
                    success:function(data){
                        if(data){
                            layer.close(index);
                            layer.msg('修改成功');
                        }else{
                            layer.msg('修改失败');
                        }
                    },
                    error:function () {
                    }
                });

            });
        });
    </script>
</body>
</html>